<?php
include_once("$config[webroot]/module/promo/lang/".$config['language']."/".$_GET['s'].".php");
include("module/promo/includes/promo_function.php");
if($_POST['add']&&empty($_POST['id'])){
    if(empty($_POST['catid'])){
        echo "<script type='text/javascript'>alert('请选择活动类型');history.go(-1)</script>";
    }elseif(empty($_POST['title'])){
        echo "<script type='text/javascript'>alert('活动标题不能为空');history.go(-1);</script>";
    }elseif(empty($_POST['stime'])){
        echo "<script type='text/javascript'>alert('起止时间不能为空');history.go(-1);</script>";
    }elseif(empty($_POST['etime'])){
        echo "<script type='text/javascript'>alert('起止时间不能为空');history.go(-1);</script>";
    }elseif(empty($_POST['detail'])){
        echo "<script type='text/javascript'>alert('活动详情不能为空');history.go(-1);</script>";
    }else{
    $addtime=time();
    $sql="insert into ".PROMOLIST." (catid,title,stime,etime,detail,addtime,uid) values('$_POST[catid]','$_POST[title]','".strtotime($_POST['stime'])."','".strtotime($_POST['etime'])."','$_POST[detail]','$addtime','$buid')";
    $db->query($sql);
    header("Location: ?action=m&m=promo&s=admin_promo_list&menu=info");
    }
}

if($_GET['id']){
    $sql="select * from ".PROMOLIST." where id=".$_GET['id']." and uid=$buid";
    $db->query($sql);
    $re=$db->fetchRow();
    
}
if($_POST['add']&&!empty($_POST['id'])){
    $sql="update ".PROMOLIST." set catid='".$_POST['catid']."',title='".$_POST['title']."',stime='".strtotime($_POST['stime'])."',etime='".strtotime($_POST['etime'])."',detail='".$_POST['detail']."' where id=".$_POST['id']." and uid=$buid";
    $db->query($sql);
    header("Location: ?action=m&m=promo&s=admin_promo_list&menu=info");
}



$tpl->assign("de",$re);
$output = tplfetch("admin_promo_add.htm");
?>
